<?php
require 'SqlHelper.class.php';
    //显示用户
    class EmpsService
    {
        
        function showemps($fenye)
        {
            $sqlhelp=new SqlHelp();
            // 显示所有用户
            // 构建语句查询出记录数
            $sql1 = "select count(id) from emps";
            // 执行
            $result = $sqlhelp->dqlsql($sql1);
            if (! empty($result)) {
                $rows = mysql_fetch_row($result);
                $fenye->count = $rows[0];
            }
            // 分页
            $fenye->pagecount = 3;
            $fenye->pageall = ceil($fenye->count / $fenye->pagecount);
            $fenye->pagestart = ($fenye->pagenow - 1) * $fenye->pagecount;
            $sql = "select * from emps limit ".$fenye->pagestart.",".$fenye->pagecount;
            // 执行
            $res = $sqlhelp->dqlsql($sql);
            
            while($rows=mysql_fetch_row($res))
            {
                $fenye->rows[]=$rows;
                
            }
            $fenye->show.= "<table border=1 bordercolor='green' cellspacing=0><tr><th>id</th><th>name</th><th>mail</th><th>grade</th><th>salary</th><th>删除用户</th><th>修改用户</th><tr>";
            for ($i = 0; $i < count($fenye->rows); $i ++) {
                 $fenye->show.=  "<tr>";
                for ($j = 0; $j < count($fenye->rows[$i]); $j ++) {
            
                     $fenye->show.=  "<td>" . $fenye->rows[$i][$j] . "</td>";
                }
                 $fenye->show.=  "<td><a onclick='return deleteuser()' href='handle.php?id=".$fenye->rows[$i][0]."'>删除用户</a></td><td><a href=''>修改用户</a></td>";
                 $fenye->show.=  "</tr>";
            }
            $pageup = $fenye->pagenow - 1;
            $pagedown = $fenye->pagenow + 1;
            $fenye->show.= "</table>";
            if ($fenye->pagenow != 1) {
                 $fenye->show.=  "<a href='empslist.php?pagenow=$pageup'>上一页</a>";
            }
                    for ($i = 1; $i <= $fenye->pageall; $i ++) {
            
                    if ($fenye->pagenow == $i) {
                         $fenye->show.=  $i;
                    } else {
                     $fenye->show.=  "<a href='empslist.php?pagenow=$i'>" . "$i" . "</a>&nbsp";
                    }
                    }
                    if ($fenye->pagenow != $fenye->pageall) {
                     $fenye->show.=  "<a href='empslist.php?pagenow=$pagedown'>下一页</a>";
                    }  
            return $fenye;
        }
        function empdelete($id)
        {
            $sqlhelp=new SqlHelp();
            //构建sql语句
            $sql="delete from emps where id=$id";
            return $sqlhelp->dmlsql($sql);
        }
    }
